from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-04-24 14:10:30.350296
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 24, Apr, 2021
Time: 14:10:35
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.7330
Nobs: 271.000 HQIC: -48.4489
Log likelihood: 3259.12 FPE: 5.62891e-22
AIC: -48.9293 Det(Omega_mle): 4.06248e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.431775 0.121823 3.544 0.000
L1.Burgenland 0.085227 0.060608 1.406 0.160
L1.Kärnten -0.221451 0.053324 -4.153 0.000
L1.Niederösterreich 0.090947 0.130396 0.697 0.486
L1.Oberösterreich 0.217859 0.124944 1.744 0.081
L1.Salzburg 0.262613 0.069010 3.805 0.000
L1.Steiermark 0.116828 0.087808 1.331 0.183
L1.Tirol 0.117613 0.060624 1.940 0.052
L1.Vorarlberg -0.036413 0.055807 -0.652 0.514
L1.Wien -0.055329 0.112870 -0.490 0.624
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.465948 0.141824 3.285 0.001
L1.Burgenland 0.006160 0.070558 0.087 0.930
L1.Kärnten 0.331322 0.062078 5.337 0.000
L1.Niederösterreich 0.089643 0.151804 0.591 0.555
L1.Oberösterreich -0.062771 0.145457 -0.432 0.666
L1.Salzburg 0.219105 0.080340 2.727 0.006
L1.Steiermark 0.098267 0.102224 0.961 0.336
L1.Tirol 0.137152 0.070577 1.943 0.052
L1.Vorarlberg 0.151743 0.064969 2.336 0.020
L1.Wien -0.425806 0.131401 -3.241 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.278941 0.061995 4.499 0.000
L1.Burgenland 0.097944 0.030843 3.176 0.001
L1.Kärnten -0.014446 0.027136 -0.532 0.594
L1.Niederösterreich 0.074105 0.066358 1.117 0.264
L1.Oberösterreich 0.283894 0.063583 4.465 0.000
L1.Salzburg 0.017008 0.035119 0.484 0.628
L1.Steiermark -0.000908 0.044685 -0.020 0.984
L1.Tirol 0.071315 0.030851 2.312 0.021
L1.Vorarlberg 0.078492 0.028400 2.764 0.006
L1.Wien 0.116698 0.057439 2.032 0.042
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.214653 0.059380 3.615 0.000
L1.Burgenland 0.024997 0.029542 0.846 0.397
L1.Kärnten 0.009657 0.025991 0.372 0.710
L1.Niederösterreich 0.054609 0.063558 0.859 0.390
L1.Oberösterreich 0.398269 0.060901 6.540 0.000
L1.Salzburg 0.079254 0.033637 2.356 0.018
L1.Steiermark 0.129421 0.042800 3.024 0.002
L1.Tirol 0.049714 0.029550 1.682 0.092
L1.Vorarlberg 0.081893 0.027202 3.011 0.003
L1.Wien -0.042679 0.055016 -0.776 0.438
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.488801 0.116397 4.199 0.000
L1.Burgenland 0.097671 0.057908 1.687 0.092
L1.Kärnten 0.010300 0.050949 0.202 0.840
L1.Niederösterreich 0.001179 0.124588 0.009 0.992
L1.Oberösterreich 0.125794 0.119379 1.054 0.292
L1.Salzburg 0.055760 0.065937 0.846 0.398
L1.Steiermark 0.067233 0.083897 0.801 0.423
L1.Tirol 0.208175 0.057924 3.594 0.000
L1.Vorarlberg 0.032664 0.053321 0.613 0.540
L1.Wien -0.080458 0.107843 -0.746 0.456
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.206011 0.092058 2.238 0.025
L1.Burgenland -0.012525 0.045799 -0.273 0.784
L1.Kärnten -0.008013 0.040295 -0.199 0.842
L1.Niederösterreich -0.010924 0.098535 -0.111 0.912
L1.Oberösterreich 0.417222 0.094416 4.419 0.000
L1.Salzburg 0.013125 0.052149 0.252 0.801
L1.Steiermark -0.029524 0.066353 -0.445 0.656
L1.Tirol 0.162516 0.045811 3.548 0.000
L1.Vorarlberg 0.056548 0.042171 1.341 0.180
L1.Wien 0.211227 0.085292 2.477 0.013
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.231210 0.111579 2.072 0.038
L1.Burgenland 0.018961 0.055511 0.342 0.733
L1.Kärnten -0.070396 0.048840 -1.441 0.149
L1.Niederösterreich -0.073644 0.119431 -0.617 0.537
L1.Oberösterreich 0.024108 0.114437 0.211 0.833
L1.Salzburg 0.081269 0.063207 1.286 0.199
L1.Steiermark 0.329480 0.080424 4.097 0.000
L1.Tirol 0.460782 0.055526 8.298 0.000
L1.Vorarlberg 0.147415 0.051114 2.884 0.004
L1.Wien -0.145478 0.103379 -1.407 0.159
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.196088 0.133221 1.472 0.141
L1.Burgenland 0.040420 0.066278 0.610 0.542
L1.Kärnten -0.076638 0.058312 -1.314 0.189
L1.Niederösterreich 0.114068 0.142595 0.800 0.424
L1.Oberösterreich 0.015556 0.136633 0.114 0.909
L1.Salzburg 0.198090 0.075467 2.625 0.009
L1.Steiermark 0.125863 0.096023 1.311 0.190
L1.Tirol 0.058812 0.066296 0.887 0.375
L1.Vorarlberg 0.104453 0.061028 1.712 0.087
L1.Wien 0.230768 0.123430 1.870 0.062
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.547236 0.072833 7.514 0.000
L1.Burgenland -0.018330 0.036235 -0.506 0.613
L1.Kärnten -0.017441 0.031880 -0.547 0.584
L1.Niederösterreich 0.085545 0.077958 1.097 0.272
L1.Oberösterreich 0.308073 0.074698 4.124 0.000
L1.Salzburg 0.016180 0.041258 0.392 0.695
L1.Steiermark -0.044244 0.052496 -0.843 0.399
L1.Tirol 0.080015 0.036244 2.208 0.027
L1.Vorarlberg 0.109588 0.033365 3.285 0.001
L1.Wien -0.061496 0.067480 -0.911 0.362
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.158491 0.099383 0.169280 0.222577 0.077870 0.087678 0.007699 0.161655
Kärnten 0.158491 1.000000 0.054057 0.209268 0.182850 -0.062893 0.172271 0.023757 0.304089
Niederösterreich 0.099383 0.054057 1.000000 0.245079 0.086961 0.323687 0.147632 0.022741 0.302805
Oberösterreich 0.169280 0.209268 0.245079 1.000000 0.304823 0.260057 0.093948 0.060837 0.131870
Salzburg 0.222577 0.182850 0.086961 0.304823 1.000000 0.152089 0.060768 0.089759 0.014299
Steiermark 0.077870 -0.062893 0.323687 0.260057 0.152089 1.000000 0.099036 0.099250 -0.100413
Tirol 0.087678 0.172271 0.147632 0.093948 0.060768 0.099036 1.000000 0.154506 0.146248
Vorarlberg 0.007699 0.023757 0.022741 0.060837 0.089759 0.099250 0.154506 1.000000 -0.007208
Wien 0.161655 0.304089 0.302805 0.131870 0.014299 -0.100413 0.146248 -0.007208 1.000000